

import sys
from pathlib import Path

# 动态获取项目路径
script_dir = Path(__file__).parent.absolute()
project_root = script_dir

# 添加项目路径到系统路径
sys.path.insert(0, str(project_root))

# 导入统一日志配置
from logger_config import cron_logger as logger

try:
    logger.info("开始执行每月自动任务")

    # 导入Flask应用实例
    from main import app

    # 创建应用上下文
    with app.app_context():
        from app.modules1.Auto import auto_main

        success = auto_main()

        if success:
            logger.info("每月自动任务执行完成")
        else:
            logger.error("每月自动任务执行失败")
            
except Exception as e:
    logger.error(f"执行过程中发生错误: {str(e)}")
    logger.exception("详细错误信息:")
